package com.hhq.service.Impl;

import com.hhq.entity.User;
import com.hhq.mapper.UserMapper;
import com.hhq.service.Userservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Service
public class UserserviceImpl implements Userservice {
   @Autowired
   UserMapper userMapper;

    public List<User> getAllUser() {
        return userMapper.getAllUser();
    }

    @Override
    public List<User> findUserByName(String loginname) {
        return userMapper.findUserByName(loginname);
    }

    public boolean checkAdminLogin(String loginname, String password) {
        List<User> userByName = userMapper.findUserByName(loginname);
        if (userByName.size()!=0){
            if (userByName.get(0).getPassword().equals(password))
                return true;
            return false;
        }
        return false;
    }

    @Override
    public int addUser(User user) {
       return userMapper.addUser(user);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    @RequestMapping("/deleteUser")
    @Override
    public void deleteUser(String loginname) {
        userMapper.deleteUser(loginname);
    }


}
